﻿/*
Copyright (c) 2010 Lance Ward
This software is licensed under the MIT license, except where otherwise noted.
For complete license details, refer to license.txt
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
using ADNLib;

namespace ADNCanvas
{
	//handles drawing of shapes with 2 points: Rectangle, line, ellipse, spray, shadow, freehand
	public class ToolDiPoint : Tool
	{
		public ToolDiPoint(DrawingToolType toolType)
		{
			this.toolType = toolType;
		}

		public ToolDiPoint() { }

		public override void MouseDown(PointF location, MouseButtons button, int clicks)
		{
			prevPoint = location;
			CreateShape(location);
		}

		public override void MouseMove(PointF location, MouseButtons button, int clicks)
		{
			prevPoint = location;
			if (currentShape != null) { currentShape.AppendPoint(location, true); }
		}

		public override void MouseUp(PointF location, MouseButtons button, int clicks)
		{
			prevPoint = location;
			currentShape.AppendPoint(location, true);
			OnShapeComplete(true);
			OnToolComplete(true);
		}

		public override Cursor GetToolCursor()
		{
			return Cursors.Cross;
		}

		private void CreateShape(PointF startPoint)
		{
			switch (ToolType)
			{
				case DrawingToolType.Rectangle:
					currentShape = new ShapeRectangle();
					break;
				case DrawingToolType.Ellipse:
					currentShape = new ShapeEllipse();
					break;
				case DrawingToolType.Line:
					currentShape = new ShapeLine();
					break;
				case DrawingToolType.Shadow:
					currentShape = new ShapeShadow();
					break;
                case DrawingToolType.FivePointStar:
                    currentShape = new ShapeFivePtStar();
                    break;
                case DrawingToolType.SixPointStar:
                    currentShape = new ShapeSixPtStar();
                    break;
                case DrawingToolType.RightTriangle:
                    currentShape = new ShapeRightTriangle();
                    break;
                case DrawingToolType.IsoscelesTriangle:
                    currentShape = new ShapeIsoscelesTriangle();
                    break;
                case DrawingToolType.Pentagon:
                    currentShape = new ShapePentagon();
                    break;
                case DrawingToolType.Hexagon:
                    currentShape = new ShapeHexagon();
                    break;
                case DrawingToolType.Octagon:
                    currentShape = new ShapeOctagon();
                    break;
                case DrawingToolType.Parallelogram:
                    currentShape = new ShapeParallelogram();
                    break;
                case DrawingToolType.Trapezoid:
                    currentShape = new ShapeTrapezoid();
                    break;
			}

			currentShape.AppendPoint(startPoint, true);
			currentShape.FillColor = defaultFill.Clone();
			currentShape.LineColor = defaultLine.Clone();
		}

		protected override void OnShapeComplete(bool isComplete)
		{
			base.OnShapeComplete(isComplete);
		}

		protected override void OnToolComplete(bool isComplete)
		{
			base.OnToolComplete(isComplete);
		}
	}
}
